<template>
  <div class="recruitment-management">
    <div class="page-header">
      <h2>招新管理</h2>
      <el-button type="primary" @click="handleAdd">
        <i class="el-icon-plus"></i> 发布招新
      </el-button>
    </div>

    <!-- 搜索区域 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="招新标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入招新标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位名称" prop="positionName">
        <el-input
          v-model="queryParams.positionName"
          placeholder="请输入岗位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招新状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option label="招新中" value="0" />
          <el-option label="已暂停" value="1" />
          <el-option label="已结束" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 招新列表 -->
    <el-table v-loading="loading" :data="recruitmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="招新ID" align="center" prop="recruitmentId" />
      <el-table-column label="招新标题" align="center" prop="title" :show-overflow-tooltip="true" />
      <el-table-column label="岗位名称" align="center" prop="positionName" />
      <el-table-column label="招聘人数" align="center" prop="recruitCount" />
      <el-table-column label="已申请人数" align="center" prop="appliedCount" />
      <el-table-column label="招新状态" align="center" prop="status">
        <template #default="{ row }">
          <el-tag :type="row.status === '0' ? 'success' : (row.status === '1' ? 'warning' : 'info')">
            {{ row.status === '0' ? '招新中' : (row.status === '1' ? '已暂停' : '已结束') }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="开始日期" align="center" prop="startDate" width="100">
        <template #default="{ row }">
          <span>{{ parseTime(row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束日期" align="center" prop="endDate" width="100">
        <template #default="{ row }">
          <span>{{ parseTime(row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="浏览次数" align="center" prop="viewCount" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="{ row }">
          <span>{{ parseTime(row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="{ row }">
          <el-button size="small" type="text" icon="el-icon-view" @click="() => handleView(row)">查看</el-button>
          <el-button size="small" type="text" icon="el-icon-edit" @click="() => handleUpdate(row)">修改</el-button>
          <el-button v-if="row.status === '0'" size="small" type="text" icon="el-icon-video-pause" @click="() => handleClose(row)">暂停</el-button>
          <el-button v-if="row.status === '1'" size="small" type="text" icon="el-icon-video-play" @click="() => handleReopen(row)">重新开放</el-button>
          <el-button size="small" type="text" icon="el-icon-delete" @click="() => handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改招新对话框 -->
    <el-dialog :title="title" v-model="openDialogVisible" width="800px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="招新标题" prop="title">
              <el-input v-model="form.title" placeholder="请输入招新标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位名称" prop="positionName">
              <el-input v-model="form.positionName" placeholder="请输入岗位名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="招聘人数" prop="recruitCount">
              <el-input-number v-model="form.recruitCount" :min="1" :max="100" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作地点" prop="workLocation">
              <el-input v-model="form.workLocation" placeholder="请输入工作地点" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始日期" prop="startDate">
              <!-- 简化日期选择器配置 -->
              <el-date-picker
                v-model="form.startDate"
                type="date"
                placeholder="请选择开始日期"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束日期" prop="endDate">
              <!-- 简化日期选择器配置 -->
              <el-date-picker
                v-model="form.endDate"
                type="date"
                placeholder="请选择结束日期"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="岗位描述" prop="description">
          <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请输入岗位描述" />
        </el-form-item>
        <el-form-item label="岗位要求" prop="requirements">
          <el-input v-model="form.requirements" type="textarea" :rows="3" placeholder="请输入岗位要求" />
        </el-form-item>
        <el-form-item label="工作时间" prop="workTime">
          <el-input v-model="form.workTime" placeholder="请输入工作时间" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleCancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 查看招新详情对话框 -->
    <el-dialog title="招新详情" v-model="viewDialogVisible" width="800px" append-to-body>
      <div v-if="viewData" class="recruitment-detail">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="招新标题">{{ viewData.title }}</el-descriptions-item>
          <el-descriptions-item label="岗位名称">{{ viewData.positionName }}</el-descriptions-item>
          <el-descriptions-item label="招聘人数">{{ viewData.recruitCount }}</el-descriptions-item>
          <el-descriptions-item label="已申请人数">{{ viewData.appliedCount }}</el-descriptions-item>
          <el-descriptions-item label="招新状态">
            <el-tag :type="viewData.status === '0' ? 'success' : (viewData.status === '1' ? 'warning' : 'info')">
              {{ viewData.status === '0' ? '招新中' : (viewData.status === '1' ? '已暂停' : '已结束') }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="浏览次数">{{ viewData.viewCount }}</el-descriptions-item>
          <el-descriptions-item label="开始日期">{{ parseTime(viewData.startDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="结束日期">{{ parseTime(viewData.endDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="工作地点">{{ viewData.workLocation }}</el-descriptions-item>
          <el-descriptions-item label="工作时间">{{ viewData.workTime }}</el-descriptions-item>
          <el-descriptions-item label="联系人">{{ viewData.contactPerson }}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{ viewData.contactPhone }}</el-descriptions-item>
        </el-descriptions>
        <div style="margin-top: 20px;">
          <h4>岗位描述</h4>
          <p>{{ viewData.description }}</p>
          <h4>岗位要求</h4>
          <p>{{ viewData.requirements }}</p>
          <h4 v-if="viewData.remark">备注</h4>
          <p v-if="viewData.remark">{{ viewData.remark }}</p>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { 
  listRecruitment, 
  getRecruitment, 
  addRecruitment, 
  updateRecruitment, 
  deleteRecruitment,
  publishRecruitment,
  closeRecruitment,
  reopenRecruitment,
  getRecruitmentsByClub
} from '@/api/campus/club/recruitment'
import { getMyClubContext } from '@/api/campus/club/clubInfo'

export default {
  name: 'RecruitmentManagement',
  dicts: ['recruitment_status'],
  data() {
        return {
          // 遮罩层
          loading: true,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 招新表格数据
          recruitmentList: [],
          // 弹出层标题
          title: '',
          // 对话框显示状态
          openDialogVisible: false,
          // 查看对话框显示状态
          viewDialogVisible: false,
          // 查看数据
          viewData: null,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            title: null,
            positionName: null,
            status: null
          },
          // 表单参数
          form: {
            recruitmentId: null,
            clubId: null,
            title: '',
            positionName: '',
            recruitCount: null,
            appliedCount: 0,
            status: '0',
            startDate: null,
            endDate: null,
            description: '',
            requirements: '',
            workTime: '',
            workLocation: '',
            contactPerson: '',
            contactPhone: '',
            remark: ''
          },
      // 表单校验
      rules: {
        title: [
          { required: true, message: '请输入招新标题', trigger: 'blur' },
          { min: 1, max: 50, message: '招新标题长度1-50个字符', trigger: 'blur' }
        ],
        positionName: [
          { required: true, message: '请输入岗位名称', trigger: 'blur' },
          { min: 1, max: 20, message: '岗位名称长度1-20个字符', trigger: 'blur' }
        ],
        recruitCount: [
          { required: true, message: '请输入招新人数', trigger: 'blur' },
          { type: 'number', min: 1, message: '招新人数必须大于0', trigger: 'blur' }
        ],
      startDate: [
        { required: true, message: '请选择开始日期', trigger: 'change' },
        {
          validator: (rule, value, callback) => {
            if (!value) {
              callback();
              return;
            }
            // 开始日期变更时，重新验证结束日期
            if (this.form.endDate && this.$refs.formRef) {
              this.$refs.formRef.validateField('endDate');
            }
            callback();
          },
          trigger: 'change'
        }
      ],
      endDate: [
        { required: true, message: '请选择结束日期', trigger: 'change' },
        {
          validator: (rule, value, callback) => {
            if (!value) {
              callback(new Error('请选择结束日期'));
            } else if (this.form.startDate && value <= this.form.startDate) {
              callback(new Error('结束日期必须大于开始日期'));
            } else {
              callback();
            }
          },
          trigger: 'change'
        }
      ],
        description: [
          { required: true, message: '请输入岗位描述', trigger: 'blur' },
          { min: 1, max: 500, message: '岗位描述长度1-500个字符', trigger: 'blur' }
        ],
        requirements: [
          { required: true, message: '请输入招聘要求', trigger: 'blur' },
          { min: 1, max: 500, message: '招聘要求长度1-500个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询招新列表 */
    async getList() {
      console.log('开始获取招新列表...')
      try {
        this.loading = true
        console.log('正在获取社团上下文信息...')
        const ctx = await getMyClubContext()
        console.log('社团上下文信息获取结果:', ctx)
        
        const clubId = ctx?.data?.clubId
        console.log('获取到的clubId:', clubId)
        
        // 检查clubId是否有效，避免调用API时出现null值
        if (!clubId) {
          // 如果clubId为null或无效，使用空列表
          console.warn('未获取到有效的clubId，显示空列表')
          this.recruitmentList = []
          this.total = 0
          this.loading = false
          return
        }
        
        // 只有clubId有效时才调用API
        console.log('使用clubId', clubId, '获取招新列表...')
        const response = await getRecruitmentsByClub(clubId)
        console.log('招新列表获取结果:', response)
        
        this.recruitmentList = response?.data || []
        this.total = this.recruitmentList.length
        console.log('招新列表加载完成，共', this.total, '条数据')
      } catch (error) {
        console.error('获取招新列表失败:', error)
        // API调用失败时使用空列表并显示错误信息
        this.recruitmentList = []
        this.total = 0
        this.$modal.msgError('获取招新列表失败：' + (error?.message || '未知错误'))
      } finally {
        this.loading = false
        console.log('招新列表加载完成')
      }
    },
    // 取消按钮
    handleCancel() {
      this.openDialogVisible = false
      // 重置表单
      if (this.$refs.formRef) {
        this.$refs.formRef.resetFields()
      }
    },
    // 表单重置
    reset() {
      this.form = {
        recruitmentId: null,
        clubId: null,
        title: '',
        positionName: '',
        recruitCount: 1,
        workLocation: null,
        workTime: null,
        contactPerson: null,
        contactPhone: null,
        startDate: null,
        endDate: null,
        status: '0',
        remark: null,
        description: '',
        requirements: ''
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log('搜索按钮被点击，查询参数:', this.queryParams)
      try {
        this.queryParams.pageNum = 1
        this.getList()
      } catch (error) {
        console.error('搜索操作失败:', error)
        this.$modal.msgError('搜索操作失败：' + (error?.message || '未知错误'))
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      console.log('重置按钮被点击')
      try {
        // 确保查询表单引用存在
        if (this.$refs['queryForm']) {
          this.$refs['queryForm'].resetFields()
        } else {
          // 如果表单引用不存在，手动重置查询参数
          this.queryParams = {
            pageNum: 1,
            pageSize: 10,
            title: null,
            positionName: null,
            status: null
          }
          console.warn('查询表单引用不存在，已手动重置查询参数')
        }
        this.handleQuery()
      } catch (error) {
        console.error('重置操作失败:', error)
        this.$modal.msgError('重置操作失败：' + (error?.message || '未知错误'))
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recruitmentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      console.log('发布招新按钮被点击')
      try {
        this.title = '发布招新'
        // 重置表单
        if (this.$refs.formRef) {
          this.$refs.formRef.resetFields()
        }
        // 清空表单数据，日期字段初始化为null而非字符串
        this.form = {
          recruitmentId: null,
          clubId: null,
          title: '',
          positionName: '',
          recruitCount: null,
          appliedCount: 0,
          status: '0',
          startDate: null,
          endDate: null,
          description: '',
          requirements: '',
          workTime: '',
          workLocation: '',
          contactPerson: '',
          contactPhone: '',
          remark: ''
        }
        // 显示对话框
        this.openDialogVisible = true
        console.log('招新对话框已打开')
      } catch (error) {
        console.error('发布招新对话框打开失败:', error)
        this.$modal.msgError('打开发布招新对话框失败：' + (error?.message || '未知错误'))
      }
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      console.log('修改按钮被点击，数据:', row)
      try {
        if (!row || !row.recruitmentId) {
          this.$modal.msgError('请选择要修改的招新信息')
          return
        }
        
        this.title = '修改招新'
        // 获取详情
        const response = await getRecruitment(row.recruitmentId)
        if (response && response.data) {
          // 确保日期字段正确处理
          const formData = { ...response.data }
          
          // 如果从API返回的是字符串格式的日期，转换为Date对象
          if (formData.startDate && typeof formData.startDate === 'string') {
            formData.startDate = new Date(formData.startDate)
          }
          if (formData.endDate && typeof formData.endDate === 'string') {
            formData.endDate = new Date(formData.endDate)
          }
          
          this.form = formData
          // 显示对话框
          this.openDialogVisible = true
          console.log('修改对话框已打开')
        } else {
          this.$modal.msgError('获取招新详情失败：返回数据为空')
        }
      } catch (error) {
        console.error('修改操作失败:', error)
        this.$modal.msgError('修改操作失败：' + (error?.message || '未知错误'))
      }
    },
    /** 查看按钮操作 */
    handleView(row) {
      console.log('查看按钮被点击，数据:', row)
      try {
        if (!row) {
          this.$modal.msgError('无效的招新信息')
          return
        }
        // 深拷贝确保不会意外修改原数据
        this.viewData = JSON.parse(JSON.stringify(row))
        this.viewDialogVisible = true
        console.log('查看详情对话框已打开')
      } catch (error) {
        console.error('查看招新详情失败:', error)
        this.$modal.msgError('查看招新详情失败：' + (error?.message || '未知错误'))
      }
    },
    /** 提交按钮 */
    async submitForm() {
      console.log('提交表单:', this.form)
      try {
        // 验证表单
        if (this.$refs.formRef) {
          await this.$refs.formRef.validate()
          console.log('表单验证通过')
        }
        
        // 格式化日期为字符串，确保符合yyyy-MM-dd格式
        const formData = { ...this.form }
        if (formData.startDate instanceof Date) {
          formData.startDate = this.formatDate(formData.startDate)
        }
        if (formData.endDate instanceof Date) {
          formData.endDate = this.formatDate(formData.endDate)
        }
        
        // 验证日期格式
        if (!this.validateDate(formData.startDate)) {
          this.$modal.msgError('开始日期格式不正确，请选择有效的日期')
          return
        }
        if (!this.validateDate(formData.endDate)) {
          this.$modal.msgError('结束日期格式不正确，请选择有效的日期')
          return
        }
        
        // 显示加载中
        this.$modal.loading('正在处理中，请稍候...')
        
        // 确保clubId存在
        if (!formData.clubId) {
          const ctx = await getMyClubContext()
          if (ctx && ctx.data && ctx.data.clubId) {
            formData.clubId = ctx.data.clubId
            console.log('添加clubId:', formData.clubId)
          } else {
            this.$modal.msgError('获取社团信息失败，请刷新页面重试')
            return
          }
        }
        
        let result
        if (this.form.recruitmentId) {
          console.log('执行修改操作:', formData)
          result = await updateRecruitment(formData)
        } else {
          console.log('执行新增操作:', formData)
          // 使用publishRecruitment代替addRecruitment
          result = await publishRecruitment(formData)
        }
        
        console.log('操作结果:', result)
        if (result && result.code === 200) {
          this.$modal.msgSuccess(this.form.recruitmentId ? '修改成功' : '发布成功')
          this.openDialogVisible = false
          this.getList()
        } else {
          this.$modal.msgError(result?.msg || '操作失败')
        }
      } catch (error) {
        console.error('提交表单失败:', error)
        // 如果是表单验证失败，不显示额外错误消息
        if (error.name !== 'ValidateError') {
          this.$modal.msgError('提交失败：' + (error?.message || '未知错误'))
        }
      } finally {
        this.$modal.closeLoading()
      }
    },
    
    /** 格式化日期为yyyy-MM-dd字符串 */
    formatDate(date) {
      if (!date) return ''
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      return `${year}-${month}-${day}`
    },
    /** 验证日期格式是否正确 */
    validateDate(dateString) {
      if (!dateString) return false
      // 正则表达式验证yyyy-MM-dd格式
      const dateRegex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
      if (!dateRegex.test(dateString)) {
        return false;
      }
      // 检查日期是否有效
      const date = new Date(dateString)
      return date instanceof Date && !isNaN(date)
    },
    
    /** 删除招新 */
    async handleDelete(row) {
      console.log('删除按钮被点击，数据:', row)
      try {
        const recruitmentIds = row ? row.recruitmentId : this.ids
        if (!recruitmentIds || (Array.isArray(recruitmentIds) && recruitmentIds.length === 0)) {
          this.$modal.msgError('请选择要删除的招新信息')
          return
        }
        await this.$modal.confirm('确定要删除选中的招新信息吗？', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        
        await deleteRecruitment(recruitmentIds)
        this.getList()
        this.$modal.msgSuccess('删除成功')
      } catch (error) {
        console.error('删除招新失败:', error)
        // 如果是用户取消操作，则不显示错误消息
        if (error.message !== 'cancel') {
          this.$modal.msgError('删除失败：' + (error?.message || '未知错误'))
        }
      }
    },
    /** 暂停招新 */
    async handleClose(row) {
      console.log('暂停按钮被点击，数据:', row)
      try {
        if (!row || !row.recruitmentId) {
          this.$modal.msgError('无效的招新信息')
          return
        }
        
        // 检查状态：后端期望状态为'1'表示进行中（注意与数据库定义不同）
        console.log('当前招新状态:', row.status, '状态类型:', typeof row.status)
        const statusValue = row.status?.toString() || ''
        console.log('转换后的状态值:', statusValue)
        
        // 根据后端实现，状态'0'表示可以关闭的进行中招聘
        if (statusValue !== '0') {
          console.error('状态检查失败，当前状态不允许暂停')
          this.$modal.msgError('只能暂停招新中的招聘')
          return
        }
        
        // 确认对话框
        await this.$modal.confirm('是否确认暂停招新"' + row.title + '"？')
        
        // 调用暂停API
        console.log('调用暂停API，招聘ID:', row.recruitmentId)
        await closeRecruitment(row.recruitmentId)
        this.$modal.msgSuccess('暂停成功')
        this.getList()
      } catch (error) {
        console.error('暂停招新失败:', error)
        // 如果是用户取消操作，不显示错误消息
        if (!error.message?.includes('cancel')) {
          // 直接显示后端返回的错误信息，避免重复判断
          const errorMsg = error?.response?.data?.msg || error?.message || '暂停操作失败'
          this.$modal.msgError(errorMsg)
        }
      }
    },
    /** 重新开放招新 */
    async handleReopen(row) {
      console.log('重新开放按钮被点击，数据:', row)
      try {
        if (!row || !row.recruitmentId) {
          this.$modal.msgError('无效的招新信息')
          return
        }
        
        if (row.status !== '1') {
          this.$modal.msgError('只能重新开放已暂停的招聘')
          return
        }
        
        try {
          await this.$modal.confirm('是否确认重新开放招新"' + row.title + '"？')
          await reopenRecruitment(row.recruitmentId)
          this.$modal.msgSuccess('重新开放成功')
          this.getList()
        } catch (reopenError) {
          // 确认对话框取消不算错误
          if (!reopenError.message?.includes('cancel')) {
            console.error('重新开放招新失败:', reopenError)
            this.$modal.msgError('重新开放失败：' + (reopenError?.response?.data?.msg || reopenError?.message || '未知错误'))
          }
        }
      } catch (error) {
        console.error('重新开放操作处理失败:', error)
        this.$modal.msgError('重新开放操作失败：' + (error?.message || '未知错误'))
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      console.log('导出按钮被点击')
      try {
        // 导出功能实现
        this.download('campus/recruitment/export', this.queryParams, `招新信息_${new Date().getTime()}.xlsx`)
          .then(() => {
            this.$modal.msgSuccess('导出成功')
          })
          .catch(() => {
            this.$modal.msgError('导出失败，请稍后重试')
          })
      } catch (error) {
        console.error('导出操作失败:', error)
        this.$modal.msgError('导出操作失败：' + (error?.message || '未知错误'))
      }
    }
  }
}
</script>

<style scoped>
.recruitment-management {
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  color: #303133;
}

.recruitment-detail {
  padding: 20px 0;
}

.recruitment-detail h4 {
  color: #303133;
  margin: 20px 0 10px 0;
}

.recruitment-detail p {
  color: #606266;
  line-height: 1.6;
  margin: 0;
}
</style>
